package com.erp.module.jiJian

import android.content.Context
import android.util.Log
import com.erp.bean.Twostringbean
import com.erp.contacts.Contacts
import com.erp.Interface.OnUserDataInterface
import com.erp.util.Httputil.*
import org.xutils.http.RequestParams
import org.xutils.x

/**
 * Created by Administrator on 2019/3/19/019.
 * 作者：刘洋
 */
class JiJianModel : JiJianContract.JiJianMP {
    override fun getBenZu(context: Context, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.JIJIAN_BENZU)
        getparams(context, params)
        params.addHeader("Content-Type", "application/json")
        addtoken(params)
        x.http().post(params, Call(context, onUserDataInterface))
    }

    override fun setJiJianSaoMiao(context: Context, jo: String, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.JIJIANSAOMA)
        getparams(context, params)
        addtoken(params)
        params.bodyContent = jo
        Log.d("TAAAG", "jo=$jo")
        params.addHeader("Content-Type", "application/json")
        x.http().post(params, Call(context, onUserDataInterface))
    }

    override fun getjijian(context: Context, page: Int, pagesize: Int, searchParams: List<Twostringbean>, onUserDataInterface: OnUserDataInterface) {
        val params = RequestParams(Contacts.JIJIAN)
        getparams(context, params)
        params.addBodyParameter("page", page.toString())
        params.addBodyParameter("pagesize", pagesize.toString())
        if (searchParams != null) {
            for (i in -0 until searchParams.size) {
                if (searchParams[i].string != "") {
                    params.addBodyParameter(searchParams[i].name, searchParams[i].string)
                }
            }
        }
        x.http().get<String>(params, Call(context, onUserDataInterface))
    }
}